package com.xuhun.client.controller;

import com.xuhun.client.client.UserClient;
import com.xuhun.client.entity.UserVO;
import feign.Feign;
import feign.jackson.JacksonDecoder;
import feign.jackson.JacksonEncoder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: 徐欢
 * @date: 2021/9/6 20:06
 * @description:
 */
@RestController
@RequestMapping(value = "/demo")
public class DemoController {

    @RequestMapping(value = "/query",method = RequestMethod.GET)
    public UserVO queryUser(){
        UserClient userClient = Feign.builder()
                //添加解码器
                .decoder(new JacksonDecoder())
                //添加编码器
                .encoder(new JacksonEncoder())
                .target(UserClient.class, "http://127.0.0.1:10080");
        return userClient.queryUser(1);

    }

    @RequestMapping(value = "/save",method = RequestMethod.GET)
    public UserVO saveUser(){
        UserClient userClient = Feign.builder()
                //添加解码器
                .decoder(new JacksonDecoder())
                //添加编码器
                .encoder(new JacksonEncoder())
                .target(UserClient.class, "http://127.0.0.1:10080");
        return userClient.saveUser(new UserVO(1,"张三"));

    }
}
